<style>
</style>

<template>
  <Form ref="formItem" :model="formItem" :label-width="120">
    <card :bordered="false" :dis-hover="true">
      <Tabs type="card">
        <TabPane label="工作时间">
          <Row>
            <Col span="4">
              <FormItem label="上班时间：">
                <TimePicker @on-change="changeStartTime" v-model="startTime" format="HH:mm" placeholder="请选择时间" style="width: 100%"></TimePicker>
              </FormItem>
            </Col>
            <Col span="4">
              <FormItem label="下班时间：">
                <TimePicker @on-change="changeEndTime" v-model="endTime" format="HH:mm" placeholder="请选择时间" style="width: 100%"></TimePicker>
              </FormItem>
            </Col>
          </Row>
        </TabPane>
        <TabPane label="预约参数">
          <card :bordered="false" :dis-hover="true">
            <p slot="title">
              <Icon type="compose"></Icon>
              患者一周只能约一次
            </p>
            <i-switch size="large" :true-value="1" :false-value="0" v-model="formItem.check1">
              <span slot="open">开启</span>
              <span slot="close">关闭</span>
            </i-switch>
          </card>
          <card :bordered="false" :dis-hover="true">
            <p slot="title">
              <Icon type="compose"></Icon>
              接待配置
            </p>
            <RadioGroup v-model="formItem.leadCare" type="button">
              <Radio label="1">
                <span>医生主导</span>
              </Radio>
              <Radio label="2">
                <span>护士主导</span>
              </Radio>
            </RadioGroup>
          </card>
          <card :bordered="false" :dis-hover="true">
            <p slot="title">
              <Icon type="compose"></Icon>
              医生预约配置(<Icon style="color: #ff9900" type="information-circled"></Icon> 如不限制请勿配置)
            </p>
            <Row>
              <Col span="4">
                <FormItem label="接待间隔 / 分钟">
                  <Input style="width: 100%" v-model="formItem.doctorInterval"></Input>
                </FormItem>
              </Col>
              <Col span="4">
                <FormItem label="接待新诊(人/次)">
                  <Input style="width: 100%" v-model="formItem.doctorReceptionNew"></Input>
                </FormItem>
              </Col>
              <Col span="4">
                <FormItem label="接待复诊(人/次)">
                  <Input style="width: 100%" v-model="formItem.doctorReceptionOld"></Input>
                </FormItem>
              </Col>
            </Row>
          </card>
          <card :bordered="false" :dis-hover="true">
            <p slot="title">
              <Icon type="compose"></Icon>
              护士预约配置(<Icon style="color: #ff9900" type="information-circled"></Icon> 如不限制请勿配置)
            </p>
            <Row>
              <Col span="4">
                <FormItem label="接待间隔 / 分钟">
                  <Input style="width: 100%" v-model="formItem.nurseInterval"></Input>
                </FormItem>
              </Col>
              <Col span="4">
                <FormItem label="接待新诊(人/次)">
                  <Input style="width: 100%" v-model="formItem.nurseReceptionNew"></Input>
                </FormItem>
              </Col>
              <Col span="4">
                <FormItem label="接待复诊(人/次)">
                  <Input style="width: 100%" v-model="formItem.nurseReceptionOld"></Input>
                </FormItem>
              </Col>
            </Row>
          </card>
        </TabPane>
        <TabPane label="小票打印">
          <card :bordered="false" :dis-hover="true">
            <p slot="title">
              <Icon type="compose"></Icon>
              小票自动打印
            </p>
            <i-switch size="large" :true-value="1" :false-value="0" v-model="formItem.autoPrint">
              <span slot="open">开启</span>
              <span slot="close">关闭</span>
            </i-switch>
          </card>
        </TabPane>
        <TabPane label="考勤配置">
          <Row>
            <Col span="4">
              <FormItem label="请假提前时间">
                <Input v-model="formItem.advanceTime" placeholder="" style="width: 50%"></Input> / 小时
              </FormItem>
            </Col>
          </Row>
        </TabPane>
        <Button type="info" @click="save" slot="extra">保存</Button>
      </Tabs>
    </card>
  </Form>
</template>

<script>
    export default {
        data () {
            return {
                baseURL: '/user/sysConfig',
                spinShow: false,
                startTime: '',
                endTime: '',
                formItem: {
                    id: '',
                    startTime: '',
                    endTime: '',
                    doctorInterval: '',
                    doctorReceptionNew: '',
                    doctorReceptionOld: '',
                    nurseInterval: '',
                    nurseReceptionNew: '',
                    nurseReceptionOld: '',
                    leadCare: '',
                    autoPrint: '',
                    advanceTime: '',
                    check1: ''
                }
            }
        },
        methods: {
            init () {
                let url = this.baseURL + '/findOne'
                this.$ajax.get(url).then((response) => {
                    let {code, data, msg} = response.data
                    if (code === 0) {
                        this.formItem = data
                        this.startTime = data.startTime
                        this.endTime = data.endTime
                    } else {
                        this.$bus.alert('error', msg)
                    }
                })
            },
            save () {
                let url = this.baseURL + '/saveOrUpdate'
                this.$ajax.post(url, this.formItem).then((response) => {
                    let {code, data, msg} = response.data
                    if (code === 0) {
                        this.$bus.alert('success', '保存成功')
                        this.formItem = data
                    } else {
                        this.$bus.alert('error', msg)
                    }
                })
            },
            changeStartTime (value, type) {
                this.formItem.startTime = value
            },
            changeEndTime (value, type) {
                this.formItem.endTime = value
            },
            close () {
                this.$bus.closePageToLink()
            }
        },
        mounted () {
            this.init()
        },
        watch: {
            '$route' (to, from) {
                if (to.path === '/config') {
                    this.init()
                }
            }
        }
    }
</script>

<style>

</style>
